<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

</head>
<style>
    .container{
        position: relative;

    }
    .outer {
        width: 500px;
        height: 100px;
        overflow: auto ;
        margin: auto ;
    }
    .outer:hover .left, .right {
        /* display: block; */
        opacity: 1;
    }
    .left , .right {
        position: absolute;
        top: 50%;
        width: 0;
        height: 0;
        border:  20px solid transparent;
        transform: translate(0, -50%);
        opacity: 1;
        transition: opacity .2s;
    }
    .left {
        border-right-color: thistle;
        left: -20px;
    }
    .right {
        border-left-color: thistle;
        right: -0px;
    }
    .inner {
        display: flex;
        width: auto;
        height: 100%;
    }
    .el {
        flex: 0 0 300px;
        border: rgb(162, 10, 233) solid ;
    }
</style>
<body>
    
    <div class="container">
        <div   onclick="scrollLeft()" class="left"></div>
        <div class="right"></div>
        <div class="outer">
       <!-- 滚动会把相对定位在容器上的元素一起滚动 -->
            <div class="inner">
                <div class="el"></div>
                <div class="el"></div>
                <div class="el"></div>
                <div class="el"></div>
                <div class="el"></div>
            </div>
        </div>
    </div>
    <script>
         function scrollLeft(){
             wraper.scrollLeft -= 50
         }
         function scrollRight(){
             wraper.scrollLeft += 50
         }
        let leftbtn = document.querySelector('.left');
        leftbtn.addEventListener('click', scrollLeft)
        let rightbtn = document.querySelector('.right');
        rightbtn.addEventListener('click', scrollRight)
        let wraper = document.querySelector( '.outer' );
        wraper.addEventListener('scroll', (e)=> {
            console.log(e)
        })
 
    </script>
</body>
</html>